package com.example.demo;

import com.example.demo.cafe.domain.Cafe;
import com.example.demo.cafe.domain.DrinkType;
import com.example.demo.cafe.domain.Order;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;

@SpringBootApplication
public class DemoApplication {

    public static void main(String[] args) {
//        ==== 方法1 begin ====
//        ApplicationContext applicationContext = SpringApplication.run(DemoApplication.class, args);
//        Cafe cafe = applicationContext.getBean(Cafe.class);
//        ==== 方法1 end   ====

//        ==== 方法2 begin ====
        ConfigurableApplicationContext context =
                new SpringApplicationBuilder(DemoApplication.class)
                        .web(WebApplicationType.NONE)
                        .run(args);
        Cafe cafe = context.getBean(Cafe.class);
//        ==== 方法2 end   ====

//        ==== 方法3 begin ====
//        spring.main.web-application-type=none
//        ==== 方法3 end   ====
        for (int i = 1; i <= 100; i++) {
            Order order = new Order(i);
            order.addItem(DrinkType.LATTE, 2, false);
            order.addItem(DrinkType.MOCHA, 3, true);
            order.addItem(DrinkType.CAPPUCCINO,2,false);
            order.addItem(DrinkType.ESPRESSO,1,false);
            System.out.println(String.format("new order[%s] is place,please wait;",order));
            cafe.placeOrder(order);
        }
//        context.close();
    }
}